home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Other Stuff / Other Stuff ’97 / PowerOS Development / basic kernel source / exception_handler.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-24  |  5.3 KB  |  228 lines  |  [TEXT/R*ch]

  1. /*
  2.         exception_handler.c
  3.     exception handlers for PowerOS
  4.         copyright 1996-1997 by Ben Martz
  5.         all rights reserved world wide
  6.  
  7.         ANY AND ALL MODIFICATIONS TO THIS SOURCE MUST CREDIT THE ORIGINAL
  8.         AUTHOR, BEN MARTZ (benmartz@ic.net), AND MUST BE GIVEN TO THE AUTHOR
  9.         FOR INTEGRATION INTO THE MAIN PowerOS SOURCE TREE. THANK YOU FOR YOUR
  10.         COOPERATION!
  11. */
  12.  
  13. #include "poweros_types.h"
  14. #include "debug_console.h"
  15.  
  16. /*********************************************************************/
  17.  
  18. void SystemReset(void) {
  19.     unsigned long    x,y;
  20.     
  21.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  22.     dprintf("SystemReset");
  23.     /* do stuff here */
  24.     cgotoxy(x,y);
  25.     __asm__ volatile("b _SystemReset_exit");
  26. }
  27.  
  28. /*********************************************************************/
  29.  
  30. void MachineCheck(void) {
  31.     unsigned long    x,y;
  32.     
  33.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  34.     dprintf("MachineCheck");
  35.     /* do stuff here */
  36.     cgotoxy(x,y);
  37.     __asm__ volatile("b _MachineCheck_exit");
  38. }
  39.  
  40. /*********************************************************************/
  41.  
  42. typedef struct {
  43.     unsigned long    reserved_on_601    : 1;
  44.     unsigned long    not_in_hash    : 1;
  45.     unsigned long    cleared        : 2;
  46.     unsigned long    protected    : 1;
  47.     unsigned long    io_err        : 1;
  48.     unsigned long    store_or_load    : 1;
  49.     unsigned long    cleared_2    : 2;
  50.     unsigned long    ea_matches    : 1;
  51.     unsigned long    cleared_3    : 1;
  52.     unsigned long    eciwx_or_ecowx    : 1;
  53.     unsigned long    cleared_4    : 20;
  54. } DSISR_BITS;
  55.  
  56. void DataStorage(void) {
  57.     unsigned long    x,y;
  58.     unsigned long    dar;
  59.     DSISR_BITS    dsisr;
  60.     
  61.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  62.     dprintf("DataStorage");
  63.     
  64.     /* get the DAR and DSISR */
  65.     __asm__ volatile("mfspr    %0,19" : "=r" (dar));
  66.     __asm__ volatile("mfspr %0,18" : "=r" (dsisr));
  67.  
  68.     /* the DAR contains the address of the first byte
  69.         of the attempted access */
  70.     dprintf(" at 0x%x : ",dar);
  71.  
  72.     /* the DSISR contains some bits that tell us what happened */
  73.     if(dsisr.not_in_hash) dprintf("not_in_hash ");
  74.     if(dsisr.protected) dprintf("protected ");
  75.     if(dsisr.io_err) dprintf("io_err ");
  76.     if(dsisr.store_or_load) dprintf("(store) ");
  77.     else dprintf("(load) ");
  78.     if(dsisr.ea_matches) dprintf("ea_matches ");
  79.     if(dsisr.eciwx_or_ecowx) dprintf("eciwx_or_ecowx");
  80.     
  81.     cgotoxy(x,y);
  82.     __asm__ volatile("b _DataStorage_exit");
  83. }
  84.  
  85. /*********************************************************************/
  86.  
  87. void InstructionStorage(void) {
  88.     unsigned long    x,y;
  89.     unsigned long    addr;
  90.     
  91.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  92.     dprintf("InstructionStorage");
  93.  
  94.     /* SRR0 contains the address of the next instruction
  95.         to the executed */
  96.     __asm__ volatile("mfsrr0 %0" : "=r" (addr));
  97.     
  98.     dprintf(" at 0x%x",addr);
  99.     
  100.     cgotoxy(x,y);
  101.     __asm__ volatile("b _InstructionStorage_exit");
  102. }
  103.  
  104. /*********************************************************************/
  105.  
  106. void External(void) {
  107.     unsigned long    x,y;
  108.     
  109.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  110.     dprintf("External");
  111.     /* do stuff here */
  112.     cgotoxy(x,y);
  113.     __asm__ volatile("b _External_exit");
  114. }
  115.  
  116. /*********************************************************************/
  117.  
  118. void Alignment(void) {
  119.     unsigned long    x,y;
  120.     
  121.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  122.     dprintf("Alignment");
  123.     /* do stuff here */
  124.     cgotoxy(x,y);
  125.     __asm__ volatile("b _Alignment_exit");
  126. }
  127.  
  128. /*********************************************************************/
  129.  
  130. void Program(void) {
  131.     unsigned long    x,y;
  132.     
  133.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  134.     dprintf("Program");
  135.     /* do stuff here */
  136.     cgotoxy(x,y);
  137.     __asm__ volatile("b _Program_exit");
  138. }
  139.  
  140. /*********************************************************************/
  141.  
  142. void FPUnavailable(void) {
  143.     unsigned long    x,y;
  144.     
  145.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  146.     dprintf("FPUnavailable");
  147.     /* do stuff here */
  148.     cgotoxy(x,y);
  149.     __asm__ volatile("b _FPUnavailable_exit");
  150. }
  151.  
  152. /*********************************************************************/
  153.  
  154. void Decrementer(void) {
  155.     unsigned long    x,y;
  156.     
  157.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  158.     dprintf("Decrementer");
  159.     /* do stuff here */
  160.     cgotoxy(x,y);
  161.     __asm__ volatile("b _Decrementer_exit");
  162. }
  163.  
  164. /*********************************************************************/
  165.  
  166. void IOException(void) {
  167.     unsigned long    x,y;
  168.     
  169.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  170.     dprintf("IOException");
  171.     /* do stuff here */
  172.     cgotoxy(x,y);
  173.     __asm__ volatile("b _IOException_exit");
  174. }
  175.  
  176. /*********************************************************************/
  177.  
  178. void SystemCall(unsigned long call) {
  179.     unsigned long    x,y;
  180.     
  181.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  182.     dprintf("SystemCall(%x)",call);
  183.     switch(call) {
  184.         case 0x1234:
  185.             dprintf(" HI!");
  186.             break;
  187.         default:
  188.             dprintf(" unknown system call!");
  189.     }
  190.     cgotoxy(x,y);
  191.     __asm__ volatile("b _SystemCall_exit");
  192. }
  193.  
  194. /*********************************************************************/
  195.  
  196. void Trace(void) {
  197.     unsigned long    x,y;
  198.     
  199.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  200.     dprintf("Trace");
  201.     /* do stuff here */
  202.     cgotoxy(x,y);
  203.     __asm__ volatile("b _Trace_exit");
  204. }
  205.  
  206. /*********************************************************************/
  207.  
  208. void FPAssist(void) {
  209.     unsigned long    x,y;
  210.     
  211.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  212.     dprintf("FPAssist");
  213.     /* do stuff here */
  214.     cgotoxy(x,y);
  215.     __asm__ volatile("b _FPAssist_exit");
  216. }
  217.  
  218. /*********************************************************************/
  219.  
  220. void UnknownException(void) {
  221.     unsigned long    x,y;
  222.     
  223.     x = cgetx(); y = cgety(); cgotoxy(1,20);
  224.     dprintf("UnknownException");
  225.     cgotoxy(x,y);
  226.     __asm__ volatile("b _UnknownException_exit");
  227. }
  228.